import defaultSettings from './defaultSettings'; // https://umijs.org/config/

import slash from 'slash2';
import webpackPlugin from './plugin.config';
const { pwa, primaryColor } = defaultSettings; // preview.pro.ant.design only do not use in your production ;
// preview.pro.ant.design 专用环境变量，请不要在你的项目中使用它。

const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION } = process.env;
const isAntDesignProPreview = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site';
const plugins = [
  [
    'umi-plugin-react',
    {
      antd: true,
      dva: {
        hmr: true,
      },
      locale: {},
      // 移除国际化命令:yarn i18n-remove
      // dynamicImport: {
      //   loadingComponent: './components/PageLoading/index',
      //   webpackChunkName: true,
      //   level: 3,
      // },
      pwa: pwa
        ? {
            workboxPluginMode: 'InjectManifest',
            workboxOptions: {
              importWorkboxFrom: 'local',
            },
          }
        : false, // default close dll, because issue https://github.com/ant-design/ant-design-pro/issues/4665
      // dll features https://webpack.js.org/plugins/dll-plugin/
      // dll: {
      //   include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
      //   exclude: ['@babel/runtime', 'netlify-lambda'],
      // },
    },
  ],
  [
    'umi-plugin-pro-block',
    {
      moveMock: false,
      // 将下载的区块中mock文件自动移动到mock文件下
      moveService: false,
      // 将下载的区块中的service文件自动移动到service文件下
      modifyRequest: true,
      // 是否使用utils文件中的request.js,如果fasle,则是使用node_modules中的umi-request库
      autoAddMenu: true, // 是否将下载的区块的路由添加到routes中,即使false,也会添加进去，只会不会显示到页面上(缺少path)
    },
  ],
]; // 针对 preview.pro.ant.design 的 GA 统计代码

if (isAntDesignProPreview) {
  plugins.push([
    'umi-plugin-ga',
    {
      code: 'UA-72788897-6',
    },
  ]);
}

export default {
  plugins,
  block: {
    // 国内用户可以使用码云
    defaultGitUrl: 'https://gitee.com/ant-design/pro-blocks', // defaultGitUrl: 'https://github.com/ant-design/pro-blocks',
  },
  hash: true,
  targets: {
    ie: 11,
  },
  devtool: isAntDesignProPreview ? 'source-map' : false,
  // umi routes: https://umijs.org/zh/guide/router.html
  routes: [
    {
      path: '/user',
      component: '../layouts/UserLayout',
      routes: [
        {
          name: 'login',
          path: '/user/login',
          component: './user/login',
        },
      ],
    },
    {
      path: '/',
      component: '../layouts/SecurityLayout',
      // 权限布局
      routes: [
        {
          path: '/',
          component: '../layouts/BasicLayoutTabs',
          routes: [
            {
              path: '/',
              redirect: '/spy/welcome',
            },
            // {
            //   path: '/welcome',
            //   name: '欢迎页',
            //   icon: 'smile',
            //   component: './Welcome',
            // },
            // {
            //   path: '/admin',
            //   name: 'admin',
            //   icon: 'crown',
            //   component: './Admin',
              
            // },
            {
              path:'/spy',
              name:'测试菜单',
              icon:'edit',
              routes:[
                {
                  path: '/spy/welcome',
                  name: '欢迎页',
                  icon: 'smile',
                  component: './Welcome',
                },
                {
                  path: '/spy/admin',
                  name: 'admin',
                  icon: 'crown',
                  component: './Admin',
                  
                },
                {
                  path: '/spy/admin1',
                  name: 'admin1',
                  icon: 'crown',
                  component: './Admin',
                  
                },
                {
                  path: '/spy/admin2',
                  name: 'admin2',
                  icon: 'crown',
                  component: './Admin',
                  
                },
                {
                  path: '/spy/admin3',
                  name: 'admin3',
                  icon: 'crown',
                  component: './Admin',
                  
                },
              ]
            },
            {
              path:'/404',
              name:'404',
              // hideChildrenInMenu: true,
              hideInMenu: true,
              component: './404',
            },
          ],
        },
      ],
    },
  ],
  // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  theme: {
    'primary-color': primaryColor,
  },
  define: {
    ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
      ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量，请不要在你的项目中使用它。
  },
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
  disableRedirectHoist: true,
  cssLoaderOptions: {
    modules: true,
    getLocalIdent: (context, _, localName) => {
      if (
        context.resourcePath.includes('node_modules') ||
        context.resourcePath.includes('ant.design.pro.less') ||
        context.resourcePath.includes('global.less')
      ) {
        return localName;
      }

      const match = context.resourcePath.match(/src(.*)/);

      if (match && match[1]) {
        const antdProPath = match[1].replace('.less', '');
        const arr = slash(antdProPath)
          .split('/')
          .map(a => a.replace(/([A-Z])/g, '-$1'))
          .map(a => a.toLowerCase());
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }

      return localName;
    },
  },
  manifest: {
    basePath: '/',
  },
  chainWebpack: webpackPlugin,
  proxy: {
    '/apiv1': {
      target: 'http://staging.qiuzhi99.com/',
      changeOrigin: true,
      pathRewrite: {
        '^/apiv1': '/api',
      },
    },
  },
};
